package pe.edu.unmsm.fisi.sysllabus.negocio.servicio.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import pe.edu.unmsm.fisi.sysllabus.integracion.dao.PlanEstudioDAO;
import pe.edu.unmsm.fisi.sysllabus.negocio.modelo.dto.PlanEstudioDTO;
import pe.edu.unmsm.fisi.sysllabus.negocio.servicio.PlanEstPeriodoAcademicoService;
import pe.edu.unmsm.fisi.sysllabus.negocio.servicio.PlanEstudioService;

@Service
public class PlanEstudioServiceImpl implements PlanEstudioService {

	@Resource
	PlanEstudioDAO planEstudioDAO;
	@Resource
	PlanEstPeriodoAcademicoService planEstPeriodoAcademicoService;
	
	@Override
	public List<PlanEstudioDTO> listarPlanesEstudioPorCarrera(
			Integer idCarreraProf) throws DataAccessException {
		return planEstudioDAO.listPlanesEstudioPorCarrera(idCarreraProf);
	}
	@Override
	public void guardarPlanEstudio(PlanEstudioDTO plan)
			throws DataAccessException {
		if (plan.getIdPlanEstudio()==null)
			planEstudioDAO.insertPlanEstudio(plan);
		else
			planEstudioDAO.updatePlanEstudio(plan);
	}
	@Override
	public PlanEstudioDTO obtenerPlanEstudio(Integer idPlanEstudio)
			throws DataAccessException {
		PlanEstudioDTO plan=planEstudioDAO.getPlanEstudio(idPlanEstudio);
		plan.setPeriodosAcademicos(planEstPeriodoAcademicoService.listarPeriodosAcademicosxPlan(idPlanEstudio));
		return plan;
	}
	@Override
	public PlanEstudioDTO obtenerPlanEstudioxidCurso(Integer idCurso) {
		return planEstudioDAO.getplanEstudioxIdCurso(idCurso);
	}

}
